include io.asm

stack segment stack
	dw 128 dup (?)
stack ends

;;======================================================================
data segment
	Head db "Vasilenko Anatoly. Group 111.$"
	Input db "Enter please sequence: $"
	Output1 db "Yes, Balanced.$"
	Output2 db "No, Not balanced.$"
data ends
;;======================================================================

code segment 'code'
	assume ss:stack, ds:data, cs:code
start:
	mov ax,data
	mov ds,ax
	lea dx, Head
	outstr
	newline
	newline
	;;------------------------------------------------------------------
		lea dx, Input;
		outstr;
		
		mov cx, 0;
		
		L:	inch al;
	
			cmp al, '.';
			je short Check;
	
			cmp al, ')';
			jne Next1;
			dec cx;
			cmp cx, 0;
			jl Bad_answ;
		Next1:
			cmp al, '(';
			jne L;
			inc cx;
			
			jmp L;
	
	Check:
		cmp cx, 0;
		jne bad_answ;
		lea dx, Output1
		outstr;
		jmp the_end;
		
	Bad_answ:
		lea dx, Output2;
		outstr;
	
	;;------------------------------------------------------------------
	
the_end:
	newline;
	mov ah,8
	int 21h
    finish
code ends

;;======================================================================
end start 

;;======================================================================
